<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title>网站信息</title>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/pintuer.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/admin.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/bootstrap.min.css">

    <script src="https://cdn.bootcss.com/jquery/1.11.1/jquery.js"></script>
    <script src="${pageContext.request.contextPath}/admin/js/pintuer.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/admin/js/my-jQ.js"></script>
    <style>
        a{
            text-decoration: none;
        }
    </style>
    <script>
        function Uploadpicture() {
            $("#File").trigger("click");
        }

        function changepic(f) {
            var rd = new FileReader();
            var files = f.files[0];
            rd.readAsDataURL(files);
            rd.onloadend = function (ev) {
                var url1 = document.getElementById("url1");
                url1.setAttribute("data-image", this.result);
                var fliename = document.getElementById("File").value;
                $("#url1").val(fliename);
            }
        }

        function del(id,picPath) {
            if (confirm('你确定要删除吗?')) {
                location.href = '${pageContext.request.contextPath}/WorkServlet?method=deleteInfo&id='+id+'&picPath='+picPath;
            } else {
                // 不删除
            }
        }
    </script>


</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 内容列表</strong></div>
    <table class="table table-hover text-center">
        <tr>
            <th width="5%">ID</th>
            <th>成就简介</th>
            <th>图片URL</th>
            <th>类别</th>
            <th width="250">操作</th>
        </tr>


        <!--  弹窗样式  -->

        <c:set var="i" value="0"/>
        <c:forEach items="${works.list}" var="work">
            <c:set var="i" value="${i+1}"/>
        <tr>
            <td>${work.id}</td>
            <td>${work.name}</td>
            <td><img width="120" height="50"  src="${pageContext.request.contextPath}/${work.picPath}?random=${randomNum}"/>
            </td>
            <td><p>${work.category}</p></td>
            <div class="modal fade" id="myModal-achievement${i}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button data-dismiss="modal" class="close" type="button">
                                <span class="sr-only">Close</span>
                            </button>
                            <h4 class="modal-title">提问</h4>
                        </div>
                        <form action="${pageContext.request.contextPath}/WorkServlet?method=updateWork&id=${work.id}"
                              method="post" enctype="multipart/form-data">
                            <div class="modal-body">
                                <p style="margin-top: 10px; text-align: center">成就名称</p>
                                <input class="form-control" type="text" name="name" value="${work.name}">
                                <p style="margin-top: 10px; text-align: center">图片</p>
                                <input class="form-control" type="file" name="img"
                                       style="padding-left: 35%; padding-bottom: 35px">
                                <p style="margin-top: 10px; text-align: center">类别</p>
                                <div style="text-align: center">
                                    <div style="margin-top: 10px">
                                        <div class="dropdown">
                                            <button type="button" class="btn dropdown-toggle" id="dropdownMenu"
                                                    data-toggle="dropdown" style="width: 158px">
                                                分类选择
                                                <span class="caret"></span>
                                            </button>

                                            <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu"
                                                style="margin-left: 36%">
                                                <li role="presentation">
                                                    <input type="checkbox" value="web" name="category"
                                                           style="margin-left: 20px">Web
                                                </li>
                                                <li role="presentation">
                                                    <input type="checkbox" value="app" name="category"
                                                           style="margin-left: 20px">App
                                                </li>
                                                <li role="presentation">
                                                    <input type="checkbox" value="competition" name="category"
                                                           style="margin-left: 20px">Competition
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                    </p>
                                </div>
                                <div class="modal-footer">
                                    <button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
                                    <button class="btn btn-primary" type="submit">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <td>
                    <div class="button-group">
                        <button type="button" class="button border-main" data-target="#myModal-achievement${i}"
                                data-toggle="modal"><span class="icon-edit"></span> 修改
                        </button>
                        <a class="button border-red" href="javascript:void(0)" onclick="del('${work.id}','${work.picPath}')"
                           style="text-decoration: none"><span
                                class="icon-trash-o"></span> 删除</a>
                    </div>
                </td>
            </div>
        </tr>
        </c:forEach>
        <tr>
            <td colspan="5">
                <div class="pagelist">
                    <c:if test="${works.pageNo != 1}">
                        <a style="text-decoration: none" href="${pageContext.request.contextPath}/WorkServlet?method=adminGetWorks&page=${works.pageNo - 1}">上一页</a>
                    </c:if>
                    <c:forEach begin="1" end="${works.totalPage}" var="i">
                        <a style="text-decoration: none" href="${pageContext.request.contextPath}/WorkServlet?method=adminGetWorks&page=${i}">${i}</a>
                    </c:forEach>
                    <c:if test="${works.pageNo != works.totalPage}">
                        <a style="text-decoration: none" href="${pageContext.request.contextPath}/WorkServlet?method=adminGetWorks&page=${works.pageNo + 1}">下一页</a>
                    </c:if>
                </div>
            </td>
        </tr>
    </table>

</div>


<div class="panel admin-panel margin-top">
    <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加内容</strong></div>
    <div class="body-content">
        <form method="post" class="form-x" enctype="multipart/form-data"
              action="${pageContext.request.contextPath}/WorkServlet?method=addWorkDisplay">
            <div class="form-group">
                <div class="label">
                    <label>标题：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" name="name" value="" data-validate="required:请输入标题"/>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>图片：</label>
                </div>
                <div class="field">
                    <input type="text" id="url1" name="img" class="input tips" style="width:25%; float:left;"
                           data-toggle="hover" data-place="right" data-image=""/>
                    <input type="file" style="display: none" id="File" name="picture" onchange="changepic(this)">
                    <input type="button" class="button bg-blue margin-left" id="image1" value="+ 浏览上传"
                           style="float:left;" onclick="Uploadpicture();">
                    <div class="tipss">图片尺寸：1920*200</div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>类别：</label>
                </div>
                <div>
                    <div style="margin-top: 10px">
                        <div class="dropdown">
                            <button type="button" class="btn dropdown-toggle" id="dropdownMenuT"
                                    data-toggle="dropdown" style="width: 158px">
                                分类选择
                                <span class="caret"></span>
                            </button>

                            <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenuT"
                                style="margin-left: 10%">
                                <li role="presentation">
                                    <input type="checkbox" value="web" name="category" style="margin-left: 20px">Web
                                </li>
                                <li role="presentation">
                                    <input type="checkbox" value="app" name="category" style="margin-left: 20px">app
                                </li>
                                <li role="presentation">
                                    <input type="checkbox" value="competition" name="category"
                                           style="margin-left: 20px">Competition
                                </li>
                            </ul>
                        </div>
                    </div>
                    </p>

                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label></label>
                </div>
                <div class="field">
                    <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
</html>
